package com.vfa.vocaburay;

import java.util.ArrayList;

import com.vfa.data.Category;
import com.vfa.data.CategoryData;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class CategoryActivity extends Activity {
     private Button insertButton;
        private Button deleteButton;
        private ListView listView;
        private CategoryData category;
        public static final int MAX_LENGHT = 10;
        private ArrayList<String> categoryInit  = new ArrayList<String> (MAX_LENGHT);
     @Override
	public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.listview);
            insertButton = (Button) findViewById(R.id.insertButton);
            deleteButton = (Button) findViewById(R.id.cancelButton);
            deleteButton.setText("Delete category");
            category = new CategoryData(getApplicationContext());
            listView = (ListView) findViewById(R.id.ListView001);
            insertButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // Perform action on click
                    Intent intent = new Intent(CategoryActivity.this, InSertCategory.class);
                    startActivity(intent);
                    CategoryActivity.this.finish();
                }

            });
            deleteButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(CategoryActivity.this, DeleteCategory.class);
                    startActivity(intent);
                    CategoryActivity.this.finish();
                }
            });
            ArrayList<Category>categoryName = new ArrayList<Category >();
            categoryName = category.getDatabase();
         for(int i=0;i<categoryName.size();i++){
             if(categoryName.get(i)!= null){
                 categoryInit.add(categoryName.get(i).getCategoryName());
                 Log.e("LocNNT", "test du lieus ne =========================="+categoryName.get(i).getCategoryName());
             }
         }
         
         ArrayAdapter<String> speechAdapter = new ArrayAdapter<String>(this, R.layout.listiterm, categoryInit);
         listView.setAdapter(speechAdapter);
     }
     private boolean checkCategoryAvailable(String name) {
         // TODO Auto-generated method stub
         ArrayList<Category >categoryName = new ArrayList<Category >();
         categoryName = category.getDatabase();
         for(int i=0;i<categoryName.size();i++){
              if(name.equals(categoryName.get(i).getCategoryName())){
                  return true;
              }
         }
         return false;
     }

}
